package com.nidu.demo.common.enums;

import cn.hutool.core.util.ArrayUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 角色标识枚举
 */
@Getter
@AllArgsConstructor
public enum RoleCodeEnum {

    SUPER_ADMIN("super_admin", "超级管理员"),
    TENANT_ADMIN("tenant_admin", "租户管理员"),
    ;

    /**
     * 角色编码
     */
    private final String code;
    /**
     * 名字
     */
    private final String name;

    public static RoleCodeEnum of(String code) {
        return ArrayUtil.firstMatch(o -> o.getCode().equals(code), values());
    }

    public static boolean isSuperAdmin(String code) {
        return SUPER_ADMIN.getCode().equalsIgnoreCase(code);
    }

    public static boolean isTenantAdmin(String code) {
        return TENANT_ADMIN.getCode().equalsIgnoreCase(code);
    }
}
